package com.emser.unc.restlet.manager;

import java.io.Serializable;
import java.util.concurrent.Callable;

import org.restlet.data.ChallengeScheme;
import org.restlet.resource.ClientResource;

import com.emser.unc.restlet.CustomerResource;
import com.emser.unc.serializable.CustomerRequestDTO;

public class CustomerTransferManager extends TransferManager implements Callable<String>{

	private CustomerRequestDTO customerRequest;
	private CustomerResource customerResource;
	private Long code;

	@Override
	public void setParams(String url, String userRest, String PassRest) {
		// TODO Auto-generated method stub
		customerRequest = new CustomerRequestDTO();
		ClientResource cr = new ClientResource(url);
		cr.setRequestEntityBuffering(true);
		cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userRest, PassRest);
		customerResource = cr.wrap(CustomerResource.class);
	}

	@Override
	public void setRequest(Serializable objectDTO) {
		// TODO Auto-generated method stub
		this.customerRequest = (CustomerRequestDTO)objectDTO;
	}

	@Override
	public Serializable getResponse() {
		// TODO Auto-generated method stub
		return this.code;
	}
	
	@Override
	public String call() throws Exception {
		// TODO Auto-generated method stub
		this.code = customerResource.addCustomer(customerRequest);
		return null;
	}

}
